/****************************************************
[	Author:		Michael Mozdzierz
[	Date:		01/30/2014
[	File:		Math.cpp
[	Course:		SGD
[
****************************************************/

#include "stdafx.h"
#include "Math.h"
#include <stdlib.h>
#include <memory>

const float Math::PI = 3.14159f;

float Math::to_degrees(float radians)
{
	return radians * (180.0f / PI);
}

float Math::to_radians(float degrees)
{
	return degrees * (PI / 180.0f);
}

float Math::distance(float a, float b)
{
	return max(a, b) - min(a, b);
}

float Math::lerp(float low, float high, float weight)
{
	return low + (high - low) * weight;
}

// TO WHOM IT MAY CONCERN:
// 
// If your wondering why the blinking crikey this method takes two void pointers:
// it's because im sick of having to remake 'contains' methods in each course
// for each new 'rectangle' struct/class. So yea, for floats for 'rect', two floats
// for 'point,' she should run like a charm.
bool Math::RectContains(void* rect, void* point)
{
	float rectData[4];
	memcpy(rectData, rect, 16);
	float left = rectData[0],
		top = rectData[1],
		right = rectData[2],
		bottom = rectData[3];

	float pointData[2];
	memcpy(pointData, point, 8);
	float x = pointData[0],
		y = pointData[1];

	if (x < right && x > left &&
		y < bottom && y > top)
		return true;

	return false;
}